<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            box-sizing: border-box;
        }

        body {
            background-color: skyblue;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            margin: 0;
            /* 水平方向发生溢出时截断 */
            overflow-x: hidden;
        }

        .box {
            background-color: pink;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 400px;
            height: 200px;
            margin: 10px;
            border-radius: 50px;
            box-shadow: 10px 5px 5px rgba(0,0,0,.3);
            transform: translateX(100%);
            transition: transform 2s ease;

        }

        .box:nth-of-type(even) {
            transform: translateX(-100%);
        }

        .box.show {
            transform: translateX(0);
        }

        .box:hover {
            transform: translate(100%);
        }

        .box:hover:nth-child(2n) {
            transform: translate(-100%);
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <script>
        const boxes = document.querySelectorAll('.box')

        window.addEventListener('scroll', checkBoxes)

        checkBoxes()

        function checkBoxes() {
            const trigger = window.innerHeight / 5 * 4

            boxes.forEach(box => {
                const boxTop = box.getBoundingClientRect().top
                
                if(boxTop < trigger) {
                    box.classList.add('show')
                } else {
                    box.classList.remove('show')
                }
            })
        }
    </script>
</body>
</html>